import { Component, OnInit, AfterViewInit } from '@angular/core';
import { MdlDialogService, MdlDialogReference, MdlSnackbarService } from '@angular-mdl/core';
import { QkPartSelectorComponent, } from '../part/qkpart.component';

@Component({
    templateUrl: './qknotice-edit.component.html',
    styleUrls: ['./qknotice-edit.component.scss']
})
export class QkNoticeEditComponent implements OnInit {
    navHeight: string = "0px";
    notices: any[];
    text: string = "";
    attachments: Array<any> = new Array({ 'id': 1, 'type': 'fa-file-word-o', 'name': 'AAA.doc' }, { 'id': 2, 'type': 'fa-file-word-o', 'name': 'AAA.doc' }, { 'id': 3, 'type': 'fa-file-word-o', 'name': 'AAA.doc' });
    receivers: Array<any> = new Array();
    noticeTitle: string="";
    constructor(
        private dialogService: MdlDialogService
    ) {}

    ngOnInit() {
    }

    /**文件上传 */
    public uploadWord() {
    }

    /**显示参与者选择器 */
    public showSelectPart($event: MouseEvent) {
        /** 
        let pDialog = this.dialogService.showCustomDialog({
            component: QkPartSelectorComponent,
            providers: [{provide: CHECKED_PARTS, useValue: this.receivers}, {provide:SHOW_TAB_AUTH, useValue: 7}],
            isModal: true,
            styles: {
                'width': '350px',
                'height': '450px',
                'padding': '0px'
            },
            clickOutsideToClose: true,
            openFrom: $event,
            enterTransitionDuration: 400,
            leaveTransitionDuration: 400
        });
        
        pDialog.subscribe((dialogReference: MdlDialogReference) => {
            dialogReference.onHide().subscribe((data: any) => {
                this.receivers = data;
                this.removePart({});
            })
        });*/
    }

    /**移除参与者 */
    removePart(rowData) {
        let temp = new Array<any>();
        this.receivers.forEach(part => {
            if (part["id"] != rowData["id"]) {
                temp.push(part);
            }
        });
        this.receivers = temp;
    }

    /**移除附件 */
    removeAttachment(rowData) {
        let temp = new Array<any>();
        this.attachments.forEach(attachment => {
            if (attachment["id"] != rowData["id"]) {
                temp.push(attachment);
            }
        });
        this.attachments = temp;
    }

    onBasicUploadAuto(event){

    }
}
